package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
)

type User struct {
	Id       int64
	UserId   string
	Username string
	Score    int
}

func TestUser() {
	engine, err := xorm.NewEngine("mysql", "root:%bn@jk35@tcp(192.168.4.131:3306)/test?charset=utf8")
	if err != nil {
		fmt.Println(err)
		return
	}
	engine.ShowSQL(true)
	defer engine.Close()

	err = engine.Sync2(new(User))
	if err != nil {
		fmt.Println(err)
		return
	}

	users, err := getUsers(engine)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(users)

}

func insertUsers(engine *xorm.Engine) {
	users := []User{}
	_, err := engine.Insert(&users)
	if err != nil {
		fmt.Println("insertUsers error:", err)
		return
	}
}

func getUsers(engine *xorm.Engine) (users []User, err error) {
	err = engine.Table(User{}).Find(&users)
	if err != nil {
		fmt.Println("getUsers error:", err)
		return
	}
	return
}
